import tkinter as tk
from tkinter import ttk, simpledialog, filedialog, messagebox
from datetime import datetime
from PIL import Image, ImageTk
from .create_card import create_card_func

def add_task_func(task_name, priority, due_date, image_path, dialog):
    try:
        frames = []
        if not task_name or not priority or not due_date:
            raise ValueError("you must enter all")
        datetime.strptime(due_date, '%Y-%m-%d')  
        create_card_func(frames["To_Do"], task_name, priority, due_date, image_path)
        dialog.destroy()
    except ValueError as ve:
        messagebox.showerror("error", str(ve))
    except Exception as e:
        messagebox.showerror("unknown error", str(e))